﻿using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using System.Collections.ObjectModel;

namespace TimersXP
{
    /// <summary>A class to maintain a list of skins, import/load skins and change skins.</summary>
    /// <NOTE>In the future the Skins might contain many different sub-libraries, and perhaps meta-data for skin genre's and skin categories or themes!</NOTE>
    /// <NOTE>But all of the skins should be broken down into this one skins library.</NOTE>
    public class Skins //: INotifyPropertyChanged
    {
        #region Class Variables
        /// <summary>The list of loaded skins</summary>
        private ObservableCollection<SkinItem> loadedSkins = new ObservableCollection<SkinItem>();
        #endregion Class Variables

        #region Properties
        /// <summary>Gets or sets the observable collection of loaded skins.</summary>
        /// <value>The loaded skins observable collection.</value>
        public ObservableCollection<SkinItem> LoadedSkins
        {
            get { return this.loadedSkins; }
            set
            {
                if (this.loadedSkins != value)
                {
                    this.loadedSkins = value;
                    //OnPropertyChanged(() => this.LoadedSkins);
                }
            }
        }
        #endregion Properties

        #region Constructors
        /// <summary>Initializes a new instance of the <see cref="Skins"/> class.</summary>
        public Skins() { }

        /// <summary>Initializes a new instance of the <see cref="Skins"/> class.</summary>
        /// <param name="newSkins">The new skins.</param>
        public Skins(ObservableCollection<SkinItem> newSkins) { this.loadedSkins = newSkins; }
        #endregion Constructors

        #region Public Functions
        /// <summary>Adds the skin.</summary>
        /// <param name="newSkin">The new skin.</param>
        /// <returns>True or False to indicate if the skin was added or not.</returns>
        public Boolean AddSkin(SkinItem newSkin)
        {
            if (this.LoadedSkins.Contains(newSkin) == false)
            {
                this.LoadedSkins.Add(newSkin);
                return true;
            }
            else
                return false;                
        }

        /// <summary>Adds the skins.</summary>
        /// <param name="newSkins">The new skins.</param>
        /// <param name="BadSkins">The bad skins.</param>
        /// <returns>True or False to indicate if all of the skins were added or not.</returns>
        public Boolean AddSkins(ObservableCollection<SkinItem> newSkins, out ObservableCollection<SkinItem> BadSkins)
        {
            Boolean AllSkinsAdded = false; //Assumes false, will change it to true if all skins are added successfully.
            BadSkins = null; //Assume it is null and that everything has been added correctly, since we don't have anything to put here anyways.
            foreach (SkinItem newSkinItem in newSkins)
            {
                if (AddSkin(newSkinItem) == false)
                {
                    BadSkins.Add(newSkinItem);
                    newSkins.Remove(newSkinItem);
                    AllSkinsAdded = false;
                }
            }
            return AllSkinsAdded;
        }
        #endregion Public Functions
    }
}
